import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import { COVERS_DATA, REVIEWS_DATA, COVER_BLOG_DATA, COVER_MEMBERS_DATA, COVER_SHOP_DATA, COVER_VOTING_DATA, COVER_ARTISTS_DATA, COVER_PODCASTS_DATA, DISCOVERS_DATA ,STEAM_VIDEO_DATA} from '../actions/CoverActions';

const initialState = {
    error: null,
    covers: [],
    reviews: [],
    cover_blog: {},
    cover_artists: {},
    cover_podcasts: {},
    cover_members: {},
    cover_shop: {},
    cover_voting: {},
    discovers: {},
    steam_video: {},
}

const persistConfig = {
    key: 'cover',
    storage,
    whitelist: ['covers', 'reviews', 'cover_blog', 'cover_members', 'cover_artists', 'cover_podcasts', 'cover_shop', 'cover_voting', "discovers", "steam_video"],
}

const coverReducer = (state = initialState, action) => {
    switch (action.type) {
        case COVERS_DATA:
            return {
                ...state,
                covers: action.data,
            }
        case REVIEWS_DATA:
            return {
                ...state,
                reviews: action.data,
            }
        case COVER_BLOG_DATA:
            return {
                ...state,
                cover_blog: action.data,
            }
        case COVER_ARTISTS_DATA:
            return {
                ...state,
                cover_artists: action.data,
            }
        case COVER_PODCASTS_DATA:
            return {
                ...state,
                cover_podcasts: action.data,
            }
        case COVER_MEMBERS_DATA:
            return {
                ...state,
                cover_members: action.data,
            }
        case COVER_SHOP_DATA:
            return {
                ...state,
                cover_shop: action.data,
            }
        case COVER_VOTING_DATA:
            return {
                ...state,
                cover_voting: action.data,
            }
        case DISCOVERS_DATA:
            return {
                ...state,
                discovers: action.data,
            }
        case STEAM_VIDEO_DATA:
            return {
                ...state,
                steam_video: action.data,
            }
        default:
            return { ...state };
    }
};

export default persistReducer(persistConfig, coverReducer);